package com.luzyluis.medicalcalendar.vista;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import com.luzyluis.medicalcalendar.R;

public class MenuActivity extends ActionBarActivity
{
    Button agregar, tratamientos, calendario, datos;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);

        agregar = (Button) findViewById(R.id.btnAgregar);
        tratamientos = (Button) findViewById(R.id.btnTratamientos);
        calendario = (Button) findViewById(R.id.btnCalendario);
        datos = (Button) findViewById(R.id.btnDatos);

        agregar.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view)
            {
                lanzarActivity(1);
            }
        });

        tratamientos.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view)
            {
                lanzarActivity(2);
            }
        });
        calendario.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view)
            {
                lanzarActivity(3);
            }
        });
        datos.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view)
            {
                lanzarActivity(4);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        boolean retorno = super.onOptionsItemSelected(item);

        //noinspection SimplifiableIfStatement
        switch (id) {
            case R.id.action_agregar:
                lanzarActivity(1);
                retorno = true;
                break;
            case R.id.action_listar:
                lanzarActivity(2);
                retorno = true;
                break;
            case R.id.action_calendario:
                lanzarActivity(3);
                retorno = true;
                break;
            case R.id.action_datos:
                lanzarActivity(4);
                retorno = true;
                break;
        }

        return retorno;


    }

    public void lanzarActivity(int key)
    {
        Intent i = null;
        switch (key)
        {
            case 1: // Agregar
                i = new Intent(this, Agregar.class);
                startActivityForResult(i, 1234);
                break;
            case 2: // Tratamientos
                i = new Intent(this, Tratamientos.class);
                startActivity(i);
                break;
            case 3: // Calendario
                i = new Intent(this, Calendario.class);
                startActivity(i);
                break;
            case 4: // Datos
                i = new Intent(this, DatosPersonales.class);
                startActivity(i);
                break;
        }
    }


}
